package com.yz.lzq.liwushuo.ui.modules.home;

import android.content.Context;

import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.HomeFragmentTabLayoutBean;
import com.yz.lzq.liwushuo.ui.modules.comminterface.OnGetSharedPerfenceDataListener;
import com.yz.lzq.liwushuo.ui.setting.SettingActivityPresenter;

/**
 * Created by Administrator on 2016/12/2.
 * 1. OnGetNetDataListener<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>>
 * HomeFragment里面的TabLayout所需要的Title
 */

public class HomePresenter implements OnGetNetDataListener<HomeFragmentTabLayoutBean> {
    //身份设置的中间人层对象,用来获取用户信息
    private SettingActivityPresenter presenter = null;
    private HomeContract.HomeModelInterface modelInterface = null;
    private HomeContract.HomeFrgmentViewInterface viewInterface = null;
    private Context mContext = null;

    /**
     * 构造函数  相对固定的写法
     *
     * @param viewInterface
     */
    public HomePresenter(Context mContext, HomeContract.HomeFrgmentViewInterface viewInterface) {
        this.modelInterface = new HomeFragmentModel();
        this.viewInterface = viewInterface;
        this.mContext = mContext;
        presenter = new SettingActivityPresenter(mContext);
    }

    /**
     * 展示TabLayout标题
     */
    public void showTabLayoutTittle() {
        presenter.setOnGetUserSharedPerfence(new OnGetSharedPerfenceDataListener() {
                                                 @Override
                                                 public void onGetGenderAndGenration(int gender, int genration) {
//                                                     Log.i("tag", "onGetGenderAndGenration: ----------->>>>"+gender+"====="+genration);
                                                     modelInterface.LoadHomeFragmentTabLayoutTittle(gender, genration, HomePresenter.this);
                                                 }
                                             }
        );

    }

    /**
     * 成功获取model层的TabLayout的标题数据
     *
     * @param data
     */
 /*   @Override
    public void onGetDataSucess(List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean> data) {
        viewInterface.ShowTabLayoutTittle(data);
    }
*/
    @Override
    public void onGetDataSucess(HomeFragmentTabLayoutBean data) {
        viewInterface.ShowTabLayoutTittle(data);
    }

    /**
     * 获取model层TabLayout的标题数据失败
     *
     * @param t
     */
    @Override
    public void onGetDataFalied(Throwable t) {
    }
}
